{% extends 'main.html' %}
{% load func %}

{% block title %}
    <title>asset info</title>
{% endblock %}


{% block content %}
{% if show_detail %}
    <div class="panel-body" id="detail_page">
     <div class="tab-base">

        <!--Nav Tabs-->
        <ul class="nav nav-tabs">
            <li class="active">
                {% if form_error %}
                 <a data-toggle="tab" href="#demo-lft-tab-1" aria-expanded="false">服务器摘要  </a>
                {% else %}
                <a data-toggle="tab" href="#demo-lft-tab-1" aria-expanded="true">服务器摘要  </a>
                {% endif %}
            </li>
            <li class="">
                <a data-toggle="tab" href="#demo-lft-tab-2" aria-expanded="false">磁盘信息</a>
            </li>
            <li >
                <a data-toggle="tab" href="#demo-lft-tab-3" aria-expanded="false">内存信息</a>
            </li>

            <li >
                <a data-toggle="tab" href="#demo-lft-tab-4" aria-expanded="false">网卡信息</a>
            </li>

             <li >
                <a data-toggle="tab" href="#demo-lft-tab-5" aria-expanded="false">变更信息</a>
            </li>

             <li >
                 {% if form_error %}
                 <a data-toggle="tab" href="#demo-lft-tab-6" aria-expanded="true">修改信息</a>
                 {% else %}
                 <a data-toggle="tab" href="#demo-lft-tab-6" aria-expanded="false">修改信息</a>
                 {% endif %}
            </li>
             <li >
                <a  href="/asset/?{{ args }}" >返  回</a>
            </li>
        </ul>

        <div class="tab-content">
            {% if form_error %}
            <div id="demo-lft-tab-1" class="tab-pane fade">
            {% else %}
            <div id="demo-lft-tab-1" class="tab-pane fade active in">
            {% endif %}
                   <div class="col-lg-15">
                        <div class="panel panel-info">
                        <div class="panel-heading">
                            <h3 class="panel-title">资产信息</h3>
                        </div>
                        <div class="panel-body">

                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>类型</th>
                                            <th>状态</th>
                                            <th>机房</th>
                                            <th>标签</th>
                                            <th>业务线</th>
                                            <th>机架位置</th>
                                            <th>最近变更</th>
                                            <th>创建时间</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                            <tr>
                                                <td> {{ asset_detail.type }}</td>
                                                {% if asset_detail.id|Get_status == 0 %}
                                                    <td>在线</td>
                                                {% else %}
                                                    <td>离线</td>
                                                {% endif %}
                                                <td>{{ asset_detail.idc }}</td>
                                                <td><span class="text-muted"><i class="demo-pli-clock"></i> {{ asset_detail.tag }}</span></td>
                                                <td>{{ asset_detail.businessunit }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.cabinet_order }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.update_time }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.create_time }}</td>

                                            </tr>

                                    </tbody>
                                </table>
                            </div>


                    </div>
                        </div>
                       </div>

                   <div class="col-lg-15">
                        <div class="panel panel-info">
                        <div class="panel-heading">
                            <h3 class="panel-title">系统信息</h3>
                        </div>
                        <div class="panel-body">

                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>主机名</th>
                                            <th>序列号</th>
                                            <th>厂商</th>
                                            <th>型号</th>
                                            <th>管理ipv4</th>
                                            <th>管理ipv6</th>
                                            <th>平台</th>
                                            <th>版本</th>
                                            <th width="50px">核数</th>
                                            <th width="80px">物理核数</th>
                                            <th>cpu品牌</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                            <tr>
                                                <td> {{ asset_detail.Server.hostname }}</td>
                                                <td>{{ asset_detail.Server.sn }}</td>
                                                <td>{{ asset_detail.Server.manufacturer }}</td>
                                                <td><span class="text-muted"><i class="demo-pli-clock"></i> {{ asset_detail.Server.model }}</span></td>
                                                <td>{{ asset_detail.Server.manage_ipv4 }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.Server.manage_ipv6 }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.Server.os_platform }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.Server.os_version }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.Server.cpu_count }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.Server.cpu_physical_count }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ asset_detail.Server.cpu_model }}</td>
                                            </tr>

                                    </tbody>
                                </table>
                            </div>


                        </div>
                        </div>
                   </div>
            </div>
            <div id="demo-lft-tab-2" class="tab-pane fade">
                 <div class="col-sm-15 ">
                        <div class="panel panel-info">
                        <div class="panel-heading">
                            <h3 class="panel-title">磁盘信息</h3>
                        </div>
                        <div class="panel-body">

                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>名称</th>
                                            <th>容量</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                            {% for disk in disk_detail %}
                                            <tr>
                                               <td><i class="demo-pli-mine"></i> {{ disk.name }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ disk.size }}</td>
                                            </tr>
                                            {% endfor %}
                                    </tbody>
                                </table>
                            </div>


                    </div>
                        </div>
                       </div>
            </div>
            <div id="demo-lft-tab-3" class="tab-pane fade ">
                 <div class="col-sm-15 ">
                        <div class="panel panel-info">
                        <div class="panel-heading">
                            <h3 class="panel-title">内存信息</h3>
                        </div>
                        <div class="panel-body">

                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>频率</th>
                                            <th>容量</th>
                                            <th>SN</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                            {% for mem in mem_detail %}
                                            <tr>
                                               <td><i class="demo-pli-mine"></i> {{ mem.speed }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ mem.size }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ mem.sn }}</td>

                                            </tr>
                                            {% endfor %}
                                    </tbody>
                                </table>
                            </div>


                    </div>
                        </div>
                       </div>
            </div>
            <div id="demo-lft-tab-4" class="tab-pane fade ">
                   <div class="col-sm-15 ">
                        <div class="panel panel-info">
                        <div class="panel-heading">
                            <h3 class="panel-title">网卡信息</h3>
                        </div>
                        <div class="panel-body">

                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>名称</th>
                                            <th>MAC</th>
                                            <th>速度</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                            {% for nic in nic_detail %}
                                            <tr>
                                               <td><i class="demo-pli-mine"></i> {{ nic.name }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ nic.mac }}</td>
                                                <td><i class="demo-pli-mine"></i> {{ nic.speed }}</td>

                                            </tr>
                                            {% endfor %}
                                    </tbody>
                                </table>
                            </div>


                    </div>
                        </div>
                       </div>
            </div>
            <div id="demo-lft-tab-5" class="tab-pane fade ">

<div class="col-lg-5">
                    <h4>变更详细</h4>

                    <!-- Timeline -->
                    <!--===================================================-->
                    <div class="timeline">

                        <!-- Timeline header -->
                        <div class="timeline-header">
                            <div class="timeline-header-title bg-primary">Now</div>
                        </div>
                        {% for log in log_obj %}
                            <div class="timeline-entry">
                                <div class="timeline-stat">
                                    <div class="timeline-icon"></div>
                                    <div class="timeline-time">{{ log.change_date }}</div>
                                </div>
                                <div class="timeline-label">
                                    {% if log.log_level == 1 %}
                                        <p class="mar-no pad-btm"> 事件级别 <i><span class="label label-danger">{{ log.get_log_level_display }}</span></i></p>
                                    {% else %}
                                        <p class="mar-no pad-btm"> 事件级别 <i><span class="label label-info">{{ log.get_log_level_display }}</span></i></p>
                                    {% endif %}
                                    <blockquote class="bq-sm bq-open mar-no">{{ log.change_detail }}</blockquote>
                                </div>
                            </div>
                        {% endfor %}

                    </div>

                </div>

    </div>
            {% if form_error %}
             <div id="demo-lft-tab-6" class="tab-pane fade active in">
             {% else %}
            <div id="demo-lft-tab-6" class="tab-pane fade ">
            {% endif %}
                <div class="panel-body" id="save_asset" >
                    <div class="panel">
                        <div class="panel-heading">
                            <h3 class="panel-title">修改资产信息</h3>
                        </div>
                        <form class="form-horizontal" method="POST">
                            <div class="panel-body">
                                {% for row in obj %}
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="demo-is-inputsmall">{{ row.label }}</label>
                                    <div class="col-sm-6">
                                      <p>{{ row }}</p>{{ row.error.0 }}
                                    </div>

                                </div>
                                {% endfor %}

                                <center><p style="color: red;">{{ obj.errors.cabinet_order.0}}</p></center>
                                </div>
                            <div class="panel-footer">
                                <div class="row">
                                    <div class="col-sm-9 col-sm-offset-3">
                                        <button class="btn btn-mint" type="submit" onclick="save()">保存</button>
                                        <button class="btn btn-warning" type="reset">重填</button>
                                        <button class="btn btn-danger" onclick="save()">取消</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

            </div>
</div>
</div>
</div>
{% else %}
    <div class="panel-body" id="asset_page" >
<center><h4 style="color: red" id="error"></h4></center>
    <div class="pad-btm form-inline">
        <div class="row">
            <div class="col-sm-6 table-toolbar-left">
                <button id="demo-btn-addrow" class="btn btn-purple" onclick="return delete_asset()"> 删除资产</button>

            </div>
            <div class="col-sm-8 table-toolbar-right pull-right">

                <div class="btn-group">
                    <div class="btn-group dropdown">
                        <button data-toggle="dropdown" class="btn btn-default dropdown-toggle">
                            <i class="demo-pli-gear" id="search_field">按ip搜索</i>
                            <span class="caret"></span>
                        </button>
                        <ul role="menu" class="dropdown-menu dropdown-menu-left">
                            <li><a href="#"onclick="search_field(this)" name="manage_ipv4">按ip搜索</a></li>
                            <li><a href="#" onclick="search_field(this)" name="asset_status">按状态搜索</a></li>
                            <li><a href="#" onclick="search_field(this)" name="model">按机器型号搜索</a></li>
                            <li><a href="#" onclick="search_field(this)" name="manufacturer">按造商搜索</a></li>
                            <li><a href="#" onclick="search_field(this)" name="businessunit">按业务线搜索</a></li>
                        </ul>
                       <div class="form-group">
                             {% if not search_field %}
                             <input id="search" type="text" placeholder="Search" class="form-control" autocomplete="off" name="manage_ipv4">
                             {% else %}
                            <input id="search" type="text" placeholder="Search" class="form-control" autocomplete="off" name="{{ search_field }}" value="{{ search_text }}">
                            {% endif %}
                             <button  class="btn btn-purple" onclick="return search()"> 搜索</button>
                             <a href="/asset/"><button  class="btn btn-purple" > 显示所有</button></a>
                       </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th><input type="checkbox" onchange="choices_all(this)"></th>
                    <th>机房</th>
                    <th>类型</th>
                    <th>管理地址</th>
                    <th>业务线</th>
                    <th>制造商</th>
                    <th>型号</th>
                    <th>操作系统</th>
                    <th>状态</th>
                </tr>
            </thead>
            <tbody>
                {% for asset in all_asset %}
                    <tr>
                        <td><input type="checkbox" id="{{ asset.id }}"></td>
                        <td><a class="btn-link" href="/asset/?detail_asset_id={{ asset.id }}&args={{ args }}"> {{ asset.idc }}</a></td>
                        <td>{{ asset.type }}</td>
                        <td>{{ asset.Server.manage_ipv4 }}</td>
                        <td><span class="text-muted"><i class="demo-pli-clock"></i> {{ asset.businessunit }}</span></td>
                        <td>{{ asset.Server.manufacturer }}</td>
                        <td>{{ asset.Server.model }}</td>
                        <td><i class="demo-pli-mine"></i> {{ asset.Server.os_platform }}</td>
                        <td>
                            {% if asset.id|Get_status != 0 %}
                                <div class="label label-table label-danger">离线</div>
                            {% else %}
                                <div class="label label-table label-info">在线</div>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}

            </tbody>
        </table>
        <div class="pull-right">
            <ul class="pagination text-nowrap mar-no">
                {% page all_asset 'asset' %}
            </ul>
        </div>

    </div>
</div>
{% endif %}
<script>
    window.onload=function(){
        var field="{{ search_field }}";
        if (field){
            $('#search_field').text($('[name={{ search_field }}]').text());
        }
    };
    function go(){
        var page_num=$('#go').val();
        location.href="/asset/?page="+page_num;
    }
    function search_field(eml){
        var field=$(eml).text();
        $('#search_field').text(field);
        $('#search').attr('name',$(eml).attr('name'))
    }
    function search(){
        var search_field=$('#search').val();
        if (search_field.length == 0){
            $('#error').text('必须输入要搜索的字段！！')
            return false
        }
        else {
            location.href='/asset/?search_field='+$('#search').attr('name')+'&search_text='+search_field
        }

    }
    function delete_asset(){
        var asset_count=$('input:checked').length;
        if(asset_count <1){
            $('#error').text('你必须选择一条资产');
            return false
        }
        var choices_asset_list=[];
        $('input:checked').each(function(){
            var asset_id=$(this).attr('id');
            choices_asset_list.push(asset_id)
        });

        if(confirm('是否删除选定资产？？')){
            $.ajax({
                url:'/asset/',
                type:'DELETE',
                data:{'host_list':JSON.stringify(choices_asset_list)},
                success:function(arg){
                    location.reload()
                }
            })
        }
        else {
            return false;//用户取消删除
        }
    }
    function choices_all(eml){
       if ($(eml).prop('checked')==true){
           $('input:checkbox').prop('checked',true)
       }
       else {
           $('input:checkbox').prop('checked',false)
       }

    }

</script>
{% endblock %}
